package com.ts.enterprise.exception;

import com.ts.enterprise.enums.ApiCode;
import lombok.Getter;
import lombok.Setter;

/**
 * 业务异常
 *
 * @author dean
 */
@Getter
@Setter
public class BusinessException extends RuntimeException {
    private static final long serialVersionUID = 6610083281801529147L;

    private Integer code;
    private Integer logicCode = 0;
    private String message;

    public BusinessException() {
        super(ExceptionEnum.BUSINESS_EXCEPTION.getMsg());
        this.code = ExceptionEnum.BUSINESS_EXCEPTION.getCode();
        this.message = ExceptionEnum.BUSINESS_EXCEPTION.getMsg();
    }

    public BusinessException(int code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public BusinessException(ExceptionEnum exceptionEnum) {
        super(exceptionEnum.getMsg());
        this.code = exceptionEnum.getCode();
        this.message = exceptionEnum.getMsg();
        this.logicCode = exceptionEnum.getLogic()?1:0;
    }

    public BusinessException(ExceptionEnum exceptionEnum, String msg) {
        super(exceptionEnum.getMsg());
        this.code = exceptionEnum.getCode();
        this.message = exceptionEnum.getMsg() + msg;
    }

    public BusinessException(ApiCode apiCode) {
        this.code = apiCode.getCode();
        this.message = apiCode.getMessage();
        this.logicCode = apiCode.getLogicCode();
    }
}
